let page;
const runCommond = async (browser, commond) => {
    if (!commond) return false;
    const cmd = `${commond.class.toLowerCase()}.${commond.cmd}`;
    console.log(commond, 'commond');
    switch (cmd) {
        case 'browser.newPage': {
            page = await browser.newPage();
            return true;
        }
        case 'page.goto': {
            if (!page) {
                throw new Error('请先打开新页签');
            }
            await page.goto(commond.target);
            return true;
        }
        case 'browser.close': {
            await browser.close();
            return true;
        }
        default: {
            return false;
        }
    }
};

module.exports = {
    page,
    runCommond,
};
